import fs from "fs";

function getEnvPorts(envFilePath: string): Record<string, number> {
    let ports = {};
    fs.readFileSync(envFilePath)
        .toString()
        .split("\n")
        .forEach((line: string) => {
            const [left, right] = line.split(/\s*\=\s*/);
            if (/^VITE_RENTER_.*_PORT$/.test(left)) {
                ports[
                    left
                        .replace(/^VITE_RENTER_/, "")
                        .replace(/_PORT$/, "")
                        .trim()
                        .toLocaleLowerCase()
                ] = parseInt(right.trim(), 10);
            }
        });
    return ports;
}

export { getEnvPorts };
